{extend name='admin@main'}

{block name="content"}

<script>
layui.use('upload', function(){
  var $ = layui.jquery
  ,upload = layui.upload;
  
  //普通图片上传
  var uploadInst = upload.render({
    elem: '#test1'
    ,url: '/upload/'
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#demo1').attr('src', result); //图片链接（base64）
      });
    }
    ,done: function(res){
      //如果上传失败
      if(res.code > 0){
        return layer.msg('上传失败');
      }
      //上传成功
    }
    ,error: function(){
      //演示失败状态，并实现重传
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
  });
  
  //多图片上传
  upload.render({
    elem: '#test2'
    ,url: '/upload/'
    ,multiple: true
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
      });
    }
    ,done: function(res){
      //上传完毕
    }
  });
  
  //指定允许上传的文件类型
  upload.render({
    elem: '#test3'
    ,url: '/upload/'
    ,accept: 'file' //普通文件
    ,done: function(res){
      console.log(res)
    }
  });
  upload.render({ //允许上传的文件后缀
    elem: '#test4'
    ,url: '/upload/'
    ,accept: 'file' //普通文件
    ,exts: 'zip|rar|7z' //只允许上传压缩文件
    ,done: function(res){
      console.log(res)
    }
  });
  upload.render({
    elem: '#test5'
    ,url: '/upload/'
    ,accept: 'video' //视频
    ,done: function(res){
      console.log(res)
    }
  });
  upload.render({
    elem: '#test6'
    ,url: '/upload/'
    ,accept: 'audio' //音频
    ,done: function(res){
      console.log(res)
    }
  });
  
  //设定文件大小限制
  upload.render({
    elem: '#test7'
    ,url: '/upload/'
    ,size: 60 //限制文件大小，单位 KB
    ,done: function(res){
      console.log(res)
    }
  });
  
  //同时绑定多个元素，并将属性设定在元素上
  upload.render({
    elem: '.demoMore'
    ,before: function(){
      layer.tips('接口地址：'+ this.url, this.item, {tips: 1});
    }
    ,done: function(res, index, upload){
      var item = this.item;
      console.log(item); //获取当前触发上传的元素，layui 2.1.0 新增
    }
  })
  
  //选完文件后不自动上传
  upload.render({
    elem: '#test8'
    ,url: '/upload/'
    ,auto: false
    //,multiple: true
    ,bindAction: '#test9'
    ,done: function(res){
      console.log(res)
    }
  });
  
  //拖拽上传
  upload.render({
    elem: '#test10'
    ,url: '/upload/'
    ,done: function(res){
      console.log(res)
    }
  });
  
	//多文件列表示例
	var demoListView = $('#demoList'),
	uploadListIns = upload.render({
		elem: '#testList',
		url: '{:url("upload")}',
		accept: 'file',
		multiple: true,
		auto: false,
		bindAction: '#testListAction',
		choose: function(obj) {
			var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
			//读取本地文件
			obj.preview(function(index, file, result) {
			
				//console.log(index);
				
				var tr = $(['<tr id="upload-' + index + '">', '<td>' + file.name + '</td>', '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>', '<td>等待上传</td>', '<td>', '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>', '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>', '</td>', '</tr>'].join(''));

				//单个重传
				tr.find('.demo-reload').on('click',
				function() {
					obj.upload(index, file);
				});

				//删除
				tr.find('.demo-delete').on('click',
				function() {
					delete files[index]; //删除对应的文件
					tr.remove();
					uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
				});

				demoListView.append(tr);
			});
		},
		done: function(res, index, upload) {
			console.log(res);
			
			
			//console.log(upload);
			if (res.code == 0) { //上传成功
				var tr = demoListView.find('tr#upload-' + index),
				tds = tr.children();
				var str ='<input type="hidden" name="fileurl[]" value="'+res.url+'"><input type="hidden" name="user_id[]" value="'+res.user_id+'">';
				str +='<input type="hidden" name="original_name[]" value="'+res.original_name+'"><input type="hidden" name="fileext[]" value="'+res.extension+'">';
				str +='<input type="hidden" name="filesize[]" value="'+res.size+'"><input type="hidden" name="filename[]" value="'+res.save_name+'">';
				str +='<input type="hidden" name="md5code[]" value="'+res.md5+'"><input type="hidden" name="sha1code[]" value="'+res.sha1+'">';
				
				tds.eq(2).html('<span style="color: #5FB878;">上传成功'+str+'</span>');
				tds.eq(3).html('<a href="'+res.url+'" target="new">查看</a>'); //清空操作
				return delete this.files[index]; //删除文件队列已经上传成功的文件
			}
			this.error(index, upload);
		},
		error: function(index, upload) {
			var tr = demoListView.find('tr#upload-' + index),
			tds = tr.children();
			tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
			tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
		}
	});
  
  //绑定原始文件域
  upload.render({
    elem: '#test20'
    ,url: '/upload/'
    ,done: function(res){
      console.log(res)
    }
  });
  
});
</script>



<form class="layui-form layui-card" action="{:request()->url()}"  onsubmit="return false;" data-auto="true" method="post" autocomplete="off" id="Newform">

    <div class="layui-card-body think-box-shadow padding-left-40">
	
		<blockquote class="layui-elem-quote">
		
			<span class="layui-badge layui-bg-green">在某些浏览器下，页面可能加载不完整，如果出现这种情况，请按F5重新加载页面!</span>
			&nbsp;
			<button type="button" data-reload="" class="layui-btn layui-btn-danger layui-btn-xs">刷 新</button>
		  
		</blockquote>

        <div class="layui-form-item">
            <label class="layui-form-label ">新闻标题</label>
            <div class="layui-input-block">
				<input name="title" value='{$vo.title|default=""}' required placeholder="请输入文件标题" class="layui-input">
				<!-- <textarea class="layui-textarea" name="content" id="content" style="height: 450px;">{$vo.content|default=''|raw}</textarea> -->
            </div>
        </div>


		<div class="layui-form-item nowrap">
		  <label class="layui-form-label label-required label-required-next">发布网址</label>
		  <div class="layui-input-inline margin-right-0" style="width:200px">
			<input name="docurl" value='{$vo.docurl|default="http://www.fslks.com/"}' placeholder="请输入发布网址" class="layui-input">
		   </div>
		  <label class="layui-form-label ">发 布 人</label>
		  <div class="layui-input-inline margin-right-0" style="width:200px;">
		    <input type="text" name="docauthor" value='{$vo.docauthor|default=session("admin_user.nickname")}'  placeholder="" class="layui-input" >
		  </div>

		</div>


		<div class="layui-form-item nowrap">
		  <label class="layui-form-label label-required label-required-next">发布时间</label>
		  <div class="layui-input-inline margin-right-0" style="width:200px">
			<input type="text" data-date-input="date" name="docdate" value='{$vo.docdate|format_datetime='Y-m-d'}' required placeholder="发布时间" class="layui-input" >
		   </div>
		  <label class="layui-form-label ">联系电话</label>
		  <div class="layui-input-inline margin-right-0" style="width:200px;">
		    <input type="text" name="doctel" value='{$vo.doctel|default=""}'  placeholder="" class="layui-input" >
		  </div>

		</div>
		
	
		
		<!--
        <div class="layui-form-item">
            <label class="layui-form-label label-required">科室/项目负责人</label>
            <div class="layui-input-block">
                <div id="keshifuzeren" class="xm-select-demo"></div>
            </div>
        </div>
		
		
        <div class="layui-form-item">
            <label class="layui-form-label ">收发文员/拟稿人</label>
            <div class="layui-input-block">
				<div id="shouwenwenyuan" class="xm-select-demo"></div>
            </div>
        </div>
		-->

        <div class="layui-form-item">
            <label class="layui-form-label ">新闻内容（提纲）</label>
            <div class="layui-input-block">
	<!-- <script type="text/plain" class="js-ueditor" styke="z-index:-999" id="content" name="content">{$vo.content|default=''|raw}</script> -->
				<!-- <textarea class="layui-textarea" name="content" id="content" style="height: 450px;">{$vo.content|default=''|raw}</textarea> -->
            
  <textarea name="content" style="width:90%;height:320px;">{$vo.content|default=''|raw}</textarea>		
			
			
			</div>
        </div>
		


        <div class="layui-form-item">
            <label class="layui-form-label ">办公室主任</label>
            <div class="layui-input-block">
				<div id="bangongshizhuren" class="xm-select-demo"></div>
            </div>
        </div>
		
        <div class="layui-form-item">
            <label class="layui-form-label ">科室/项目负责人</label>
            <div class="layui-input-block">
                <div id="keshifuzeren" class="xm-select-demo"></div>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label ">分管领导</label>
            <div class="layui-input-block">
				<div id="fenguanlingdao" class="xm-select-demo"></div>
            </div>
        </div>
		
        <div class="layui-form-item">
            <label class="layui-form-label ">网站发布人</label>
            <div class="layui-input-block">
				<div id="shouwenwenyuan" class="xm-select-demo"></div>
            </div>
        </div>
		
		<!--
        <div class="layui-form-item">
            <label class="layui-form-label ">主要领导</label>
            <div class="layui-input-block">
				<div id="zhuyaolingdao" class="xm-select-demo"></div>
            </div>
        </div>
		-->





		
        <div class="layui-form-item">
            <label class="layui-form-label ">文件列表</label>
            <div class="layui-input-block">
                <div class="layui-textarea padding-bottom-10" style="min-height:auto">
					<div class="layui-upload">
					  {if auth("edit") && request()->action() =='edit'  && $vo['docauthor']==session('admin_user')['nickname'] && $vo['status']!=2 }
					  <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" id="testList">选择多文件</button> &nbsp;&nbsp;
					  <button type="button" class="layui-btn layui-btn-sm" id="testListAction">开始上传</button>
					  {/if}
					  
					  {if auth("add") && request()->action() =='add'  }
					  <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" id="testList">选择多文件</button> &nbsp;&nbsp;
					  <button type="button" class="layui-btn layui-btn-sm" id="testListAction">开始上传</button>
					  {/if}				  

					  <div class="layui-upload-list">
						<table class="layui-table">
						  <thead>
							<tr><th>文件名</th>
							<th>大小</th>
							<th>状态</th>
							<th>操作</th>
						  </tr></thead>
						  <tbody id="demoList">
						  {foreach $files as $key=>$vo}
						  <tr id="upload-{$vo.id}"><td>{$vo.original_name}</td><td>{$vo.filesize|format_size}</td><td></td><td> <a target="new" href="{$vo.fileurl}">查看</a></td>  <tr>
						  {/foreach}
						  </tbody>
						</table>
					  </div>
					  
					</div> 


                </div>
            </div>
        </div>
		

		{if request()->action() =='edit'}
        <div class="layui-form-item">
            <label class="layui-form-label ">批示情况</label>
            <div class="layui-input-block">
                <div class="layui-textarea padding-bottom-10" style="min-height:auto">

						<table class="layui-table">
						  <thead>
							<tr>
							<th>批示人</th>
							<th>批示时间</th>
							<th>批示类型</th>
							<th width="164px">批示内容</th>
						  </tr></thead>
						  {foreach $list_flow as $key=>$vo}
						  <tr id="upload-{$vo.id}">
						  <td>{$vo.username}</td>
						  <td>{$vo.addtime|format_datetime='Y-m-d H:i'}</td>
						  
						  <td>                
						  {eq name='vo.types' value='nigao'}<span class="layui-bg-red">拟稿完成</span>{/eq}
						  {eq name='vo.types' value='keshifuzeren'}<span class="layui-bg-orange">科室/项目负责人审核</span>{/eq}
						  {eq name='vo.types' value='shouwenwenyuan'}<span class="layui-bg-green">发文文员/拟稿人重核</span>{/eq}
						  {eq name='vo.types' value='bangongshizhuren'}<span class="layui-bg-blue">办公室主任</span>{/eq}
						  {eq name='vo.types' value='fenguanlingdao'}<span class="layui-bg-black">分管领导</span>{/eq}
						  {eq name='vo.types' value='zhuyaolingdao'}<span class="layui-bg-gray">主要领导</span>{/eq}
						  </td>
						  
						  <td> {$vo.info}</td>  <tr>
						  {/foreach}
						</table>

                </div>
            </div>
        </div>
		{/if}


		{if request()->action() =='edit' && $rs_flow >0 && $my_flow_count ==0 }
        <div class="layui-form-item">
            <label class="layui-form-label">填写意见</label>
            <div class="layui-input-block">
				<textarea class="layui-textarea" name="info" id="info" placeholder="请填写批示意见">{$info|default=""}</textarea>
            </div>
			
        </div>
		{/if}

        <div class="layui-form-item text-center">
            {notempty name='id'}<input type="hidden" name="id" id="id" value="{$id}">{/notempty}

			<input type='hidden' value='{$docauthor}' name='docauthor'>
			{if request()->action() =='edit' && $rs_flow >0 && $my_flow_count ==0 }
			<button class="layui-btn" type='button' id="saveinfo">保存批示意见</button>
			{/if}
			
			{if request()->action() =='edit' && $docauthor == session('admin_user.nickname')  }
			<button class="layui-btn" type='submit'>流转文件</button>
			{/if}
			
			{if request()->action() =='add' }
			<button class="layui-btn" type='submit'>保存数据</button>
			{/if}
			<button class="layui-btn layui-btn-danger" onclick="hsitoryBack()" type="button">关闭</button>
        </div>

    </div>
</form>
{/block}


	
{block name='script'}
    <script type="text/javascript" charset="utf-8" src="__ROOT__/static/plugs/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="__ROOT__/static/plugs/ueditor/ueditor.all.min.js"> </script>
    <!-- <script type="text/javascript" charset="utf-8" src="__ROOT__/static/plugs/ueditor/lang/zh-cn/zh-cn.js"></script> -->
	
	
	
	
	
	<script src="__ROOT__/static/ewebeditor/4-1-7/tinymce.min.js"></script>
<script>tinymce.init({selector:'textarea',toolbar1: "undo redo | cut copy paste | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect",
        toolbar2: " searchreplace | bullist numlist | outdent indent blockquote | link unlink anchor image media code | inserttime preview | forecolor backcolor , table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft",
        menubar: false,
        toolbar_items_size: 'small',
        style_formats: [
            {title: 'Bold text', inline: 'b'},
            {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
            {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
            {title: 'Example 1', inline: 'span', classes: 'example1'},
            {title: 'Example 2', inline: 'span', classes: 'example2'},
            {title: 'Table styles'},
            {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
        ],
        templates: [
            {title: 'Test template 1', content: 'Test 1'},
            {title: 'Test template 2', content: 'Test 2'}
        ],plugins: [
            "advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
            "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
            "table contextmenu directionality emoticons template textcolor paste fullpage textcolor"
        ],language:'zh_CN'});</script>
	
	
	
	
	
	
	
	
	
	
	
	
<script type="text/javascript">

$(document).ready(function () {
	
	
     // ueditor编辑器集合
     var ueditors = {};


     // ueditor编辑器
     $('.js-ueditor').each(function() {
         var ueditor_name = $(this).attr('id');
         ueditors[ueditor_name] = UE.getEditor(ueditor_name, {
             initialFrameHeight: 400, //初始化编辑器高度,默认320
             autoHeightEnabled: false, //是否自动长高
             maximumWords: 50000, //允许的最大字符数
             //serverUrl: GV.ueditor_upload_url,
         });
		 
		 
		 
		 
         /*
         $('#' + ueditor_name + 'grabimg').click(function() {
             var con = ueditors[ueditor_name].getContent();
             $.post(GV.ueditor_grabimg_url, { 'content': con, 'type': 'images' },
                 function(data) {
                     ueditors[ueditor_name].setContent(data);
                     layer.msg("图片本地化完成");
                 }, 'html');
         })*/

     });

});



</script>

<script>

    //window.form.render();
	function hsitoryBack(){
		$.msg.confirm('确定要关闭吗？', function (index) {
			history.back(), $.msg.close(index);
		});
	};
    //require(['ckeditor', 'angular','plugs/select/xm-Select'], function () {
    require([ 'angular','plugs/select/xm-Select'], function () {
        //window.createEditor('[name="content"]', {height: 250});
		var app = angular.module("Newform", []).run(callback);

		function callback($rootScope) {
            // 返回列表
            $rootScope.hsitoryBack = function () {
                $.msg.confirm('确定要取消编辑吗？', function (index) {
                    history.back(), $.msg.close(index);
                });
            };
		}
		
		var keshifuzeren = xmSelect.render({
			el: '#keshifuzeren', 
			name: 'keshifuzeren',
			toolbar: {
				show: true,
				list: [ 'ALL', 'CLEAR', 'REVERSE' ]
			},

			theme: {
				color: '#0081ff',
			},			
			paging: true,
			pageSize: 10,
			max:2,
			filterable: true,
			data: [
				{$str}
			]
		})		
		
		var shouwenwenyuan = xmSelect.render({
			el: '#shouwenwenyuan', 
			name: 'shouwenwenyuan',
			toolbar: {
				//show: true,
				//list: [ 'ALL', 'CLEAR', 'REVERSE' ]
			},
			paging: true,
			pageSize: 10,
			filterable: true,
			theme: {
				color: '#e54d42',
			},
			model: {
				label: {
					type: 'block',
					block: {
						//最大显示数量, 0:不限制
						showCount: 3,
						//是否显示删除图标
						showIcon: true,
					}
				}
			},
			radio: true,
			data: [
				{$str}
			]
		})	
		
		var bangongshizhuren = xmSelect.render({
			el: '#bangongshizhuren', 
			filterable: true,
			name: 'bangongshizhuren',
			paging: true,
			pageSize: 10,
			toolbar: {
				//show: true,
				//list: [ 'ALL', 'CLEAR', 'REVERSE' ]
			},
			theme: {
				color: '#f37b1d',
			},

			radio: true,
			data: [
				{$str}
			]
		})
		
		var fenguanlingdao = xmSelect.render({
			el: '#fenguanlingdao', 
			filterable: true,
			name: 'fenguanlingdao',
			paging: true,
			pageSize: 10,
			toolbar: {
				show: true,
				list: [ 'ALL', 'CLEAR', 'REVERSE' ]
			},
			theme: {
				color: '#8dc63f',
			},
			model: {
				label: {
					type: 'block',
					block: {
						//最大显示数量, 0:不限制
						showCount: 3,
						//是否显示删除图标
						showIcon: true,
					}
				}
			},
			data: [
				{$str}
			]
		})
		

		
		{if isset($vo) }
		keshifuzeren.setValue([ {$keshifuzeren} ])
		
		bangongshizhuren.setValue([ {$bangongshizhuren} ])
		
		fenguanlingdao.setValue([ {$fenguanlingdao} ])
		
		shouwenwenyuan.setValue([ {$shouwenwenyuan} ])
		
		//zhuyaolingdao.setValue([ {$zhuyaolingdao} ])
		{/if}
    })
</script>

<script>
    layui.use(['layer','form' ,'jquery','layedit'], function() {
        var layer = layui.layer, $ = layui.jquery ,form = layui.form;
		var layedit = layui.layedit;


	  layedit.set({
		  uploadImage: {
			   url: '{:url('doUploadPic')}' //接口url
			  ,type: 'post' //默认post
		  }
		});
		
		
	  //建立编辑器
	  //layedit.build('content',{
//
		//  height: 300  //设置编辑器高度
	  //}); 
		
        form.render();
    });
	

	$('#saveinfo').click(function(){
		var info = $("#info").val();
		var docid =$("#id").val();

		
		if(info == ''){
			layer.msg('请填写批示意见!',{icon: 5});//失败的表情
			return ;		
		}
		
		//alert(info);
		
		var url = "/document/news/saveinfo.html";
		$.ajax({
			url:url,
			type:'post',
			data:'info='+info+'&docid='+docid,
			beforeSend:function () {
				
				this.layerIndex = layer.load(0, { shade: [0.5, '#393D49'] });
			},
			success:function(data){
				if(data.status == 'error'){
					layer.msg(data.msg,{icon: 5});//失败的表情
					return;
				}else if(data.status == 'success'){
					//layer.msg(data.msg,{icon: 6});
					layer.msg(data.msg, {
						icon: 6,//成功的表情
						time: 2000 //1秒关闭（如果不配置，默认是3秒）
					}, function(){
						//location.reload();
						window.location.href="/admin.html#/document/news/index.html?spm=m-73-74-75";
					});
				}
			},
			complete: function () {
				layer.close(this.layerIndex);
			},
		});
		return false;//阻止表单跳转
	});

</script>

<script type="text/javascript">

$(function (){
	//var editor = UE.getEditor('content');

	//setTimeout(function () { 
	//	var editor = UE.getEditor('content');

	//}, 2000);
})


</script>
{/block}